using UnityEngine;

namespace Math
{
    public struct Plane
    {
        public float a;
        public float b;
        public float c;
        public float d;

        public Plane(Vector3 a, Vector3 b, Vector3 c)
        {
            Vector3 n = Vector3.Cross(b-a, c-a).normalized;
            this.a = n.x;
            this.b = n.y;
            this.c = n.z;
            this.d = Vector3.Dot(a, n);
        }

        public Plane(float a, float b, float c, float d)
        {
            float mag = Mathf.Sqrt(a*a+b*b+c*c);
            this.a = a/mag;
            this.b = b/mag;
            this.c = c/mag;
            this.d = d/mag;
        }

        public float Dot(Vector3 p)
        {
            return a*p.x+b*p.y+c*p.z+d;
        }

        public float Dot(float x, float y, float z)
        {
            return a*x+b*y+c*z+d;
        }
    }
}